﻿namespace OutLook.Model.UnitTesting
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using OutLook.Module.Infrastructure;
    using OutLook.Model.Domains;
    using OutLook.Model.Infrastructure;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class DomainStorage : XmlRepository
    {
        public override T Create<T>()
        {
            if (typeof(T) == typeof(ChemicalСombination))
                return new ChemicalСombination() as T;

            if (typeof(T) == typeof(Charge))
                return Charge.Create() as T;

            if (typeof(T) == typeof(ChargeRowToLoad))
                return ChargeRowToLoad.Create() as T;

            if (typeof(T) == typeof(Load))
                return new Load() as T;

            if (typeof(T) == typeof(Loss))
                return Loss.Create() as T;

            if (typeof(T) == typeof(LossRowToLoad))
                return LossRowToLoad.Create() as T;

            if (typeof(T) == typeof(Model))
                return new Model() as T;

            if (typeof(T) == typeof(SubstanceFactor))
                return new SubstanceFactor() as T;

            ///TODO:Create technology
            ///TODO:Create output
            throw new NotSupportedException();
        }

        public override bool AnalysisResults()
        {
            if (CurrentModelTypeName.Equals(typeof(ChemicalСombination).Name))
                return Item<ChemicalСombination>(0).Validate();

            if (CurrentModelTypeName.Equals(typeof(Charge).Name))
                return Item<Charge>(0).Validate();

            if (CurrentModelTypeName.Equals(typeof(SubstanceFactor).Name))
                return Item<SubstanceFactor>(0).Validate();

            //if (CurrentModelTypeName.Equals(typeof(Model).Name))
             //   return Item<Model>(0).Validate();


            if (CurrentModelTypeName.Equals(typeof(Loss).Name))
                return Item<Loss>(0).Validate();

            if (CurrentModelTypeName.Equals(typeof(Output).Name))
                return Item<Output>(0).Validate();

            if (CurrentModelTypeName.Equals(typeof(LoadData).Name))
                return Item<LoadData>(0).Validate();

            if (CurrentModelTypeName.Equals(typeof(Load).Name))
                return Item<Load>(0).Validate();

            return false;
        }

        protected override void LoadTestData()
        {
            if (CurrentModelTypeName.Equals(typeof(Charge).Name))
            {
                Initialize<Charge>(GetStorageConnectionString<Charge>());

                return;
            }

            if (CurrentModelTypeName.Equals(typeof(ChemicalСombination).Name))
            {
                Initialize<ChemicalСombination>(GetStorageConnectionString<ChemicalСombination>());

                return;
            }

            if (CurrentModelTypeName.Equals(typeof(SubstanceFactor).Name))
            {
                Initialize<SubstanceFactor>(GetStorageConnectionString<SubstanceFactor>());

                return;
            }

            if (CurrentModelTypeName.Equals(typeof(Model).Name))
            {
                Initialize<Model>(GetStorageConnectionString<Model>());

                return;
            }

            if (CurrentModelTypeName.Equals(typeof(Loss).Name))
            {
                Initialize<Loss>(GetStorageConnectionString<Loss>());

                return;
            }

            if (CurrentModelTypeName.Equals(typeof(Output).Name))
            {
                Initialize<Output>(GetStorageConnectionString<Output>());

                return;
            }

            if (CurrentModelTypeName.Equals(typeof(LoadData).Name))
            {
                Initialize<LoadData>(GetStorageConnectionString<LoadData>());

                return;
            }

            if (CurrentModelTypeName.Equals(typeof(Load).Name))
            {
                Initialize<Load>(GetStorageConnectionString<Load>());

                return;
            }
        }
    }
}
